-- 切换剪刀攻击模式RPC
AddModRPCHandler("ScissorMod", "ToggleScissor", function(player)
    if player ~= nil and player.components.inventory ~= nil then
        local item = player.components.inventory:GetEquippedItem(EQUIPSLOTS.HANDS)
        if item ~= nil and item.prefab == "assn_jiandao" and item.ToggleAttackMode ~= nil then
            if item._rangedmode ~= true then
                local x, y, z = player.Transform:GetWorldPosition()
                SpawnPrefab("ghostlyelixir_speed_fx").Transform:SetPosition(x, y - 1, z)
            end
            item:ToggleAttackMode(player)
        end
    end
end)
-- 客户端监听X键
if not TheNet:IsDedicated() then
    TheInput:AddKeyDownHandler(TUNING.ASSN_JIANDAO, function()
        SendModRPCToServer(MOD_RPC["ScissorMod"]["ToggleScissor"])
    end)
end

-- 获取物品信息RPC
AddModRPCHandler("ScissorMod", "Showinfo", function(player, guid, item)
    if player.player_classified == nil or player.player_classified.net_assn_info == nil then
        return
    end
    if item ~= nil and item.components ~= nil then
        local str = ""
        -- 显示本mod特殊信息
        if item.getAssnInfo then
            local assn_info = item:getAssnInfo()
            if assn_info then
                str = str .. "\n" .. assn_info
            end
        end
        if str and str ~= "" then
            player.player_classified.net_assn_info:set(guid .. ";" .. str)
        else
            player.player_classified.net_assn_info:set("")
        end
    end
end)

-- 开启技能范围吸血斩RPC
AddModRPCHandler("ScissorMod", "Skill1", function(player)
    if player ~= nil and player.components.inventory ~= nil then
        local item = player.components.inventory:GetEquippedItem(EQUIPSLOTS.HANDS)
        if item ~= nil and item.prefab == "assn_qianren" and player.prefab == "assn_567" then
            if item.skill then
                if item.skill == 0 then
                    if item.components.rechargeable ~= nil and item.components.rechargeable:IsCharged()
                        and player.components.sanity ~= nil and player.components.hunger ~= nil and player.components.stamina ~= nil then
                        if player.components.sanity.current < 20 or player.components.hunger.current < 20 or player.components.stamina.current < 50 then
                            player.components.talker:Say("我没有充足的精神和体力")
                        else
                            player.sg:GoToState("assn_skill1")
                            item.skill = 1
                            item.components.weapon:SetRange(3.5)
                            item.components.timer:StartTimer("skillover", 60)
                        end
                    else
                        player.components.talker:Say("我需要缓一缓")
                    end
                else
                    player.components.talker:Say("我必须一心一意")
                end
            end
        end
    end
end)
-- 客户端监听R键
if not TheNet:IsDedicated() then
    TheInput:AddKeyDownHandler(TUNING.ASSN_SKILL1, function()
        SendModRPCToServer(MOD_RPC["ScissorMod"]["Skill1"])
    end)
end

-- 开启技能真实之怒RPC
AddModRPCHandler("ScissorMod", "Skill2", function(player)
    if player ~= nil and player.components.inventory ~= nil then
        local item = player.components.inventory:GetEquippedItem(EQUIPSLOTS.HANDS)
        if item ~= nil and item.prefab == "assn_qianren" and player.prefab == "assn_567" then
            if item.skill then
                if item.skill == 0 then
                    if item.components.rechargeable ~= nil and item.components.rechargeable:IsCharged()
                        and player.components.stamina then
                        if player.components.stamina.current < 50 then
                            player.components.talker:Say("我没有充足的体力")
                        else
                            player.sg:GoToState("assn_skill2")
                            item.skill = 2
                            item.components.timer:StartTimer("skillover", 60)
                        end
                    else
                        player.components.talker:Say("我需要缓一缓")
                    end
                else
                    player.components.talker:Say("我必须一心一意")
                end
            end
        end
    end
end)
-- 客户端监听G键
if not TheNet:IsDedicated() then
    TheInput:AddKeyDownHandler(TUNING.ASSN_SKILL2, function()
        SendModRPCToServer(MOD_RPC["ScissorMod"]["Skill2"])
    end)
end

-- 开启技能超巨大化RPC
AddModRPCHandler("ScissorMod", "Skill3", function(player)
    if player ~= nil and player.components.inventory ~= nil then
        local item = player.components.inventory:GetEquippedItem(EQUIPSLOTS.HANDS)
        if item ~= nil and item.prefab == "assn_qianren" and player.prefab == "assn_567" then
            if item.skill then
                if item.skill == 0 then
                    if item.components.rechargeable ~= nil and item.components.rechargeable:IsCharged()
                        and player.components.stamina ~= nil then
                        if player.components.stamina.current < 120 then
                            player.components.talker:Say("我没有充足的体力")
                        else
                            player.sg:GoToState("assn_skill3")
                            item.skill = 3
                            item.components.weapon:SetRange(5.5)
                            item.components.timer:StartTimer("skillover", TUNING.ASSN_SKILL3_TIME)
                        end
                    else
                        player.components.talker:Say("我需要缓一缓")
                    end
                else
                    player.components.talker:Say("我必须一心一意")
                end
            end
        end
    end
end)
-- 客户端监听V键
if not TheNet:IsDedicated() then
    TheInput:AddKeyDownHandler(TUNING.ASSN_SKILL3, function()
        SendModRPCToServer(MOD_RPC["ScissorMod"]["Skill3"])
    end)
end
